<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	function splitQuery(arr,target){
		let left = 0
		let right = arr.length - 1
		while(left <= right){
			const mid = Math.floor((left + right) / 2)
			if (arr[mid] === target){
				return mid
			} else if(arr[mid] > target){
				right = mid - 1
			} else if(arr[mid] < target){
				left = mid + 1
			}
		}
		return -1
	}
	const sortedArray = [1, 3, 5, 7, 9];
	
	console.log(splitQuery(sortedArray, 7)); // 输出: 3
	console.log(splitQuery(sortedArray, 2)); // 输出: -1
	console.log(splitQuery(sortedArray, 1)); // 输出: 0
	console.log(splitQuery([], 1)); // 输出: -1 （空数组）
</script>
</html>